package com.liunian.subject.common.generator;

import cn.hutool.core.lang.Snowflake;
import cn.hutool.core.lang.generator.Generator;
import cn.hutool.core.util.IdUtil;
import org.springframework.stereotype.Service;

import javax.annotation.PostConstruct;


@Service
public class CfpSnowflakeGenerator implements Generator<Long> {

    private Snowflake snowflake;

    @PostConstruct
    public void init() {
        long workerId = IdUtil.getWorkerId(1L, 31);
        snowflake = new Snowflake(null, workerId, 0, false, Snowflake.DEFAULT_TIME_OFFSET, 4095L);
    }

    @Override
    public Long next() {
        return this.snowflake.nextId();
    }
}